//
//  YJCLeftController.m
//  xiangzhe
//
//  Created by lyt on 16/11/9.
//  Copyright © 2016年 com.dazhebao. All rights reserved.
//

#import "YJCLeftController.h"
#import "YJCHeadView.h"
#import "YJCLeftList.h"
#import "YJCLeftTableViewCell.h"
#import "YJCFootView.h"

@interface YJCLeftController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSArray *listArr;

@end

@implementation YJCLeftController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupUI];
}

- (void)setupUI{
    
    self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.scrollEnabled = NO;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.tableView];
    _tableView.backgroundColor = [UIColor yt_colorWithHexString:@"#363636"];
    
    // 设置 headview 和 footview
    YJCHeadView *headV = [[YJCHeadView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 64)];
    headV.headPicture.image = [UIImage imageNamed:@"def_photo"];
    headV.nameLbale.text = @"测试 A";
    headV.rankLbale.text = @"王者";
    _tableView.tableHeaderView = headV;
    
    UITapGestureRecognizer *headTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(headViewClick:)];
    [headV addGestureRecognizer:headTap];
    
//    底部视图
    YJCFootView *footV = [[YJCFootView alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height - 44, self.view.bounds.size.width, 44)];
    [_tableView addSubview:footV];
    footV.imageV.image = [UIImage imageNamed:@"bsicon"];
    footV.lableL.text = @"设置中心";
    
    UITapGestureRecognizer *footTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(footViewClick:)];
    [footV addGestureRecognizer:footTap];
    
    // 分割线
    UIView *topView = [[UIView alloc] initWithFrame:CGRectMake(0, headV.bounds.size.height, self.view.bounds.size.width, 1)];
    topView.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:topView];
    
    UIView *buttomView = [[UIView alloc] initWithFrame:CGRectMake(0,[UIScreen mainScreen].bounds.size.height - footV.bounds.size.height, self.view.bounds.size.width, 1)];
    buttomView.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:buttomView];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.listArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString* leftViewCellID = @"leftViewcell";
    YJCLeftTableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:leftViewCellID];
    if (!cell) {
        cell = [[YJCLeftTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:leftViewCellID];
    }
    YJCLeftList *lList = self.listArr[indexPath.row];
    
    cell.iconView.image = [UIImage imageNamed:lList.icon];
    cell.nameLable.text = lList.name;
    cell.picView.image = [UIImage imageNamed:lList.pic];
    cell.backgroundColor = [UIColor yt_colorWithHexString:@"#363636"];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
}

#pragma mark - 点击事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSLog(@"%zd",indexPath.row);
    switch (indexPath.row) {
        case 0:
            NSLog(@"点击了0行");
            break;
        case 1:
            NSLog(@"点击了1行");
            break;
        case 2:
            NSLog(@"点击了2行");
            break;
        case 3:
            NSLog(@"点击了3行");
            break;
        case 4:
            NSLog(@"点击了4行");
            break;
        default:
            break;
    }
    
    
}

- (void)headViewClick:(UITapGestureRecognizer *)gesture{
    NSLog(@"跳转到头像设置页面");
    
    
}

- (void)footViewClick:(UITapGestureRecognizer *)gesture{
    
    NSLog(@"跳转到设置中心");
    
}
#pragma mark - 懒加载数据
-(NSArray *)listArr{
    
    if (!_listArr) {
        NSArray *arr = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"LeftView List" ofType:@"plist"]];
        NSMutableArray *arrM = [NSMutableArray array];
        
        for (NSDictionary *dic in arr) {
            
            YJCLeftList *leftList = [YJCLeftList initWithDic:dic];
            [arrM addObject:leftList];
        }
        
        _listArr = arrM.copy;
    }
    return _listArr;
}
@end
